package com.neusoft.edu.smartschool.app.view.activity;

import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.neu.edu.smartschool.mapplication.R;
import com.neusoft.edu.smartschool.app.parttern.presenter.MainPresenter;
import com.neusoft.edu.smartschool.app.util.NoScrollViewPager;
import org.yeruyi.common.activity.RoyBaseActivity;
import org.yeruyi.common.adapter.ViewPagerAdapter;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;


/**
 * @author: yeruyi
 * @date: 2018/5/29
 * @email: yeruyi_roy@outlook.com
 * @modify: 2018/5/29 创建文件
 */
public class MainActivity extends RoyBaseActivity<MainPresenter> implements View.OnClickListener {

    @BindView(R.id.main_nsv)
    NoScrollViewPager mMainNsv;
    @BindView(R.id.main_index_iv)
    ImageView mMainIndexIv;
    @BindView(R.id.main_index_tv)
    TextView mMainIndexTv;
    @BindView(R.id.main_index_ll)
    LinearLayout mMainIndexLl;
    @BindView(R.id.main_order_iv)
    ImageView mMainOrderIv;
    @BindView(R.id.main_order_tv)
    TextView mMainOrderTv;
    @BindView(R.id.main_order_ll)
    LinearLayout mMainOrderLl;
    @BindView(R.id.main_my_iv)
    ImageView mMainMyIv;
    @BindView(R.id.main_my_tv)
    TextView mMainMyTv;
    @BindView(R.id.main_my_ll)
    LinearLayout mMainMyLl;

    private ViewPagerAdapter mAdapter;

    @Override
    protected int initLayout() {
        return R.layout.activity_main;
    }

    @Override
    protected MainPresenter initPresenter() {
        return null;
    }

    @Override
    protected void initActionBar() {
        List<Fragment> fragmentList = new ArrayList<Fragment>();
        mAdapter = new ViewPagerAdapter(getSupportFragmentManager(), fragmentList);
        mMainIndexLl.setTag(1);
        mMainIndexLl.setOnClickListener(this);
        mMainOrderLl.setTag(2);
        mMainOrderLl.setOnClickListener(this);
        mMainMyLl.setTag(3);
        mMainMyLl.setOnClickListener(this);

    }

    @Override
    protected void initViewEvent() {
        mMainNsv.setAdapter(mAdapter);
    }

    @Override
    protected boolean initTitleStyle() {
        return false;
    }

    @Override
    public void onClick(View view) {
        if (view.getTag() != null) {
            int tagValue = Integer.parseInt(view.getTag().toString());
            if (tagValue <= 3 && tagValue >= 1) {
                initClickArea(tagValue);
            }
        }
    }

    private void initClickArea(int code) {
        mMainIndexIv.setBackgroundResource(
                code == 1 ? R.drawable.drawable_icon_home_en : R.drawable.drawable_icon_home_un
        );
        mMainIndexTv.setTextColor(
                getResources().getColor(code == 1 ? R.color.main_color_text_click : R.color.main_color_text_un)
        );
        mMainOrderIv.setBackgroundResource(
                code == 2 ? R.drawable.drawable_icon_order_en : R.drawable.drawable_icon_order_un
        );
        mMainOrderTv.setTextColor(
                getResources().getColor(code == 2 ? R.color.main_color_text_click : R.color.main_color_text_un)
        );
        mMainMyIv.setBackgroundResource(
                code == 3 ? R.drawable.drawable_icon_my_en : R.drawable.drawable_icon_my_un
        );
        mMainMyTv.setTextColor(
                getResources().getColor(code == 1 ? R.color.main_color_text_click : R.color.main_color_text_un)
        );
        mMainNsv.setCurrentItem(code);
    }
}
